package game.map 
{
	/**
	 * ...
	 * @author rnk
	 */
	public class Province 
	{
		public var uid:String;
		public var name:String;
		public var type:String;
		public var routes:Array=[];
		public var castle:int = 0;
		public var crown:int = 0;
		public var supply:int = 0;
		public var army:Army;
		
		public function Province() 
		{
			
		}
		
		public function HasRoute(province:Province):Boolean
		{
			return routes.indexOf(province.uid)>=0;
		}
		
		public function AddUnit(unit:Unit):void
		{
			if (!army)
			{
				army = new Army(this);
			} 
			army.AddUnit(unit);
		}
		
		public function AddHero(hero:Hero):void
		{
			if (!army)
			{
				army = new Army(this);
			} 
			army.AddHero(hero);
		}
		
		public function AddArmy(newArmy:Army):void
		{
			if (army)
			{
				army.Join(newArmy);
			} else
			{
				army = newArmy;
				if (newArmy.province)
				{
					newArmy.province.RemoveArmy();
				}
				newArmy.province = this;
			}
		}
		
		public function RemoveArmy():void
		{
			if (army)
				army.province = null;
			army = null;
		}
		
	}

}